package tp.pr3.commands;

import tp.pr3.Game;
import tp.pr3.MensajesConst;
import tp.pr3.Player;
import tp.pr3.commands.exceptions.CommandExecutionException;
import tp.pr3.commands.exceptions.WrongCommandFormatException;

public class LookCommand implements Command
{

	Player _pj;
	String _cad;

	public LookCommand()
	{

	}

	public LookCommand(String item, Player pers)
	{
		this._cad = item;
		this._pj = pers;
	}

	public LookCommand(Player pers)
	{
		this._pj = pers;
		this._cad = null;
	}

	@Override public void execute() throws CommandExecutionException
	{
		// TODO Auto-generated method stub
		if (this._cad == null)
		{
			System.out.println(this._pj.showItems());
		}
		else
		{
			if (this._pj.getItem(_cad) == null)
				throw new CommandExecutionException("There is no " + this._cad
						+ " in your inventory.\n>");
			else
				System.out.println(this._pj.getItem(_cad));
		}

	}

	@Override public String getHelp()
	{
		// TODO Auto-generated method stub
		return MensajesConst.help;
	}

	@Override public Command parse(String cad, Game execContext)
			throws WrongCommandFormatException
	{
		String cadena[] = cad.split(" ");

		if (cadena.length < 1 || cadena.length > 2)
			throw new WrongCommandFormatException();
		if (!(cadena[0].equalsIgnoreCase("look") || cadena[0]
				.equalsIgnoreCase("mira")))
			throw new WrongCommandFormatException();
		if (cadena.length == 1)
			return new LookCommand(execContext.getPlayer());
		return new LookCommand(cadena[1], execContext.getPlayer());
	}
}
